<template>
  <component :is="getComponentName(value.field)" :detail="results" v-loading="loading" />
  <div class="paginaTion" v-if="total > 10">
    <Pagination
      v-model:limit="pageSize"
      v-model:page="pageNo"
      :total="total"
      @pagination="getTableData"
    />
  </div>
</template>
<script setup lang="ts">
import { nodePageGet } from '@/api/ent/advanceSearch/index'
import Penalties from './components/penalties.vue'
import Abnormal from './components/abnormal.vue'
import ClearAccount from './components/clearaccount.vue'
import Simplecancell from './components/simplecancellation.vue'
import Serious from './components/serious_illegality.vue'
import Overduetaxs from './components/overduetaxs.vue'
import TaxAbnor from './components/tax_abnormal.vue'
import TaxViola from './components/tax_violations.vue'
import CheckInspec from './components/check_inspec.vue'
import FillingInfo from './components/filing_info.vue'
import OpenCourt from './components/open_court.vue'
import Courtnoticed from './components/courtnoticed.vue'
import Judgment from './components/judgment_doc.vue'
import Executed from './components/executed_person.vue'
import DishonestExecutor from './components/dishonest_executor.vue'
import RestrictConsum from './components/restrict_consumption.vue'
import FinalCase from './components/final_case.vue'
import EquityPledge from './components/equity_pledge.vue'
import KnowledgePledge from './components/knowledge_pledge.vue'
import ChattelMortgage from './components/chattel_mortgage.vue'
const props = defineProps({
  value: Object,
  cid: String
})
const loading = ref(false)
const pageNo = ref(1)
const pageSize = ref(10)
const total = ref(0)
const results = ref(null)
onMounted(() => {
  watchEffect(() => {
    if (Object.keys(props.value).length) {
      let value = JSON.parse(JSON.stringify(props.value))
      pageNo.value = value.pageNo
      pageSize.value = value.pageSize
      total.value = value.total
      results.value = value.results
    }
  })
})
const getComponentName = (field) => {
  // 行政处罚
  if (field === 'penaltiesCount') {
    return Penalties
    // 经营异常
  } else if (field === 'abnormalCount') {
    return Abnormal
    // 清算组信息
  } else if (field === 'clearAccountCount') {
    return ClearAccount
    // 简易注销公告
  } else if (field === 'simpleCancellationCount') {
    return Simplecancell
    // 严重违法
  } else if (field === 'seriousIllegalityCount') {
    return Serious
    // 欠税公告
  } else if (field === 'overdueTaxesCount') {
    return Overduetaxs
    // 税务非正常户
  } else if (field === 'taxAnomaliesCount') {
    return TaxAbnor
    // 税务违法
  } else if (field === 'taxViolationsCount') {
    return TaxViola
  }
  // 抽查检查
  else if (field === 'checkInspectCount') {
    return CheckInspec
  }
  // 立案公告
  else if (field === 'filingInfoCount') {
    return FillingInfo
  }
  // 开庭公告
  else if (field === 'openCourtCount') {
    return OpenCourt
  }
  // 法院公告
  else if (field === 'courtNoticedCount') {
    return Courtnoticed
  }
  // 裁判文书
  else if (field === 'judgmentDocCount') {
    return Judgment
  }
  // 被执行人
  else if (field === 'executedPersonCount') {
    return Executed
  }
  // 失信被执行人
  else if (field === 'dishonestExecutorCount') {
    return DishonestExecutor
  }
  // 限制高消费
  else if (field === 'restrictConsumptionCount') {
    return RestrictConsum
  }
  // 终本案件
  else if (field === 'finalCaseCount') {
    return FinalCase
  }
  // 股权出质
  else if (field === 'equityPledgeCount') {
    return EquityPledge
  }
  // 知识产权出质
  else if (field === 'knowledgePledgeCount') {
    return KnowledgePledge
  }
  // 动产抵押
  else if (field === 'chattelMortgageCount') {
    return ChattelMortgage
  }
}
const getTableData = async (val) => {
  let params = {
    pageNo: val.page,
    pageSize: val.limit,
    cid: props.cid,
    nodes: [props.value.field]
  }
  loading.value = true
  const res = await nodePageGet({ ...params })
  pageNo.value = res[props.value.field].pageNo
  pageSize.value = res[props.value.field].pageSize
  total.value = res[props.value.field].total
  results.value = res[props.value.field].results
  loading.value = false
}
</script>
<style lang="scss" scoped>
.paginaTion {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 20px 10px 0;
}
</style>
